@echo off
chcp 65001 >nul
echo 🚀 开始运行副将数据导入脚本...

REM 检查是否在正确的目录
if not exist "import-deputy-general-data.js" (
    echo ❌ 请在 nestjs-app 目录下运行此脚本
    pause
    exit /b 1
)

REM 检查数据文件是否存在
if not exist "websocket_data_2025-08-27T09-19-03-318Z.json" (
    echo ❌ 数据文件不存在: websocket_data_2025-08-27T09-19-03-318Z.json
    pause
    exit /b 1
)

REM 检查数据库表是否存在
echo 🔍 检查数据库表...
node -e "const mysql = require('mysql2/promise'); const dbConfig = { host: process.env.DB_HOST || '43.143.253.188', port: parseInt(process.env.DB_PORT) || 3306, user: process.env.DB_USER || 'nextjs', password: process.env.DB_PASS || 'yEAiRE2jcxTyRBy5', database: process.env.DB_NAME || 'nextjs', timezone: '+08:00' }; async function checkTable() { try { const connection = await mysql.createConnection(dbConfig); const [tables] = await connection.execute('SELECT COUNT(*) as count FROM information_schema.tables WHERE table_schema = ? AND table_name = \"deputy_general_base\"', [dbConfig.database]); if (tables[0].count === 0) { console.log('❌ 表 deputy_general_base 不存在，请先运行 create-deputy-general-table.sql 创建表'); process.exit(1); } console.log('✅ 表 deputy_general_base 存在'); await connection.end(); } catch (error) { console.error('❌ 检查表时发生错误:', error.message); process.exit(1); } } checkTable();"

if %errorlevel% neq 0 (
    echo ❌ 表检查失败，请先创建表
    pause
    exit /b 1
)

REM 运行导入脚本
echo 📥 开始导入数据...
node import-deputy-general-data.js

if %errorlevel% equ 0 (
    echo 🎉 导入完成！
) else (
    echo ❌ 导入失败！
    pause
    exit /b 1
)

pause 